package com.shekhar.paas.story;

import java.util.Calendar;
import java.util.Date;

import com.shekhar.paas.domain.Story;

public class StoryScorer {

    public long score(Story story){
        return score(story.getTweetCount(), story.getRetweetCount(), story.getUpdatedOn());
    }
    public long score(int tweetCount, int retweetCount, Date updateOn) {
        int score = tweetCount * 10 + retweetCount * 5;
        // double order = Math.log10(Math.max(Math.abs(score), 1));
        int sign = score > 0 ? 1 : -1;
        long seconds = updateOn.getTime() / 1000 - 1134028003;
        double val = score + ((double) sign * seconds) / 3600;
        return Math.round(val);
    }

    public static void main(String[] args) {
        Date date = new Date();
        long score = new StoryScorer().score(10, 10, date);
        System.out.println(score);
        score = new StoryScorer().score(10, 5, date);
        System.out.println(score);
        score = new StoryScorer().score(1, 1, date);
        System.out.println(score);

        Calendar instance = Calendar.getInstance();
        instance.setTime(date);
        instance.set(Calendar.HOUR_OF_DAY, instance.get(Calendar.HOUR_OF_DAY) - 1);

        Date time = instance.getTime();

        score = new StoryScorer().score(10, 10, time);
        System.out.println(score);
        score = new StoryScorer().score(10, 5, time);
        System.out.println(score);
        score = new StoryScorer().score(1, 1, time);
        System.out.println(score);
    }
}
